package org.jeecg.modules.dock.entity.mds;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.dock.entity.BaseResponseV0;
import org.jeecg.modules.dock.entity.mes.response.MesBaseResponseVO;

import java.io.Serializable;

/**
 * mds响应通用实体
 *
 * @author zhoutong
 */
@ApiModel(value = "mds响应通用实体", description = "mds响应通用实体")
@Data
@ToString(callSuper = true)
public class MdsBaseResponseVO extends BaseResponseV0 implements Serializable {

    @ApiModelProperty("返回代码（定义的错误码)没有错误时返回0")
    private Integer errcode;

    @ApiModelProperty("传输数据")
    private Object data;

    public MdsBaseResponseVO() {

    }

    public static MdsBaseResponseVO error(Object data) {
        MdsBaseResponseVO r = new MdsBaseResponseVO();
        r.setTarget(ERROR);
        r.setErrcode(400);
        r.setMsg("无");
        if(data != null){
            r.setMsg(data.toString());
        }
        return r;
    }

    public static MdsBaseResponseVO ok(Object data) {
        MdsBaseResponseVO r = new MdsBaseResponseVO();
        r.setTarget(SUCCESS);
        r.setErrcode(CommonConstant.STATUS_NORMAL);
        r.setData(data);
        r.setMsg("请求成功！");
        return r;
    }

    public static MdsBaseResponseVO ok() {
        MdsBaseResponseVO r = new MdsBaseResponseVO();
        r.setTarget(SUCCESS);
        r.setErrcode(CommonConstant.STATUS_NORMAL);
        r.setMsg("请求成功！");
        return r;
    }

    public MesBaseResponseVO toMesResponseVO(){
        MesBaseResponseVO responseVO = BeanUtil.toBean(this, MesBaseResponseVO.class);
        return responseVO;
    }

}
